<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome - Your OnLine School !</title>

<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		
		$.ajax({
			type: "GET",
			url: "HomeServlet",
			data: {type: "list2", keyWord: $('#key_word').val(), dateStart: $('#date_start').val(), loc: $('#list_locs option:selected').val()},
			success: function(data){			
				$('#myList').html(data);
				
				$("input[class='timeOut']").each(function(){
					$(this).attr("disabled",true);
				});
				
				$("input[class='stillValide']").change(function(){
					if($("input[class='stillValide']:checked").length == 0){
						$("#Register").attr("disabled", true);
					}
					else{
						$("#Register").removeAttr("disabled");
					}
				});
				
			},
			error: function(e){
				console.text(e.message);
			}
		});
		
		$.ajax({
			type: "GET",
			url: "HomeServlet",
			data: {type: "list1"},
			success: function(data){
				$('#list_locs').html(data);
			},
			error: function(e){
				console.text(e.message);
			}
		});
		
		$('#search').click(function(){
			$.ajax({
				type: "GET",
				url: "HomeServlet",
				data: {type: "list2", keyWord: $('#key_word').val(), dateStart: $('#date_start').val(), loc: $('#list_locs option:selected').val()},
				success: function(data){
					$('#myList').html(data);
					
					$("input[class='timeOut']").each(function(){
						$(this).attr("disabled",true);
					});
					
					$("input[class='stillValide']").change(function(){
						if($("input[class='stillValide']:checked").length == 0){
							$("#Register").attr("disabled", true);
						}
						else{
							$("#Register").removeAttr("disabled");
						}
					});
					
				},
				error: function(e){
					console.text(e.message);
				}
			});

		});
		
		$("#Register").attr("disabled", true);

	});
</script>
</head>
<body>

<h2>Hello ! Welcome to Your OnLine School.</h2>
<h2>Here you can find the interesting courses for you !</h2>
<h3>And you can also manage your personal informations by clicking here. </h3>
<a href="http://localhost:8080/PROJET_LO54/PersonalCentre.jsp">Manage Page<br/><br/></a>
<form name="myHomepage" method="GET" id="myPage">
	<h3>Do a research</h3>
	By key word <input type="text" name="key_word" id="key_word"/><br/>
	By date you want to start <input type="date" name="date_start" id="date_start"/><br/>
	By location <select name="locations" id="list_locs"><option></option></select><br/></br>
	<input type="button" value="Search" id="search"/><br/><br/>
</form>

<form name="myListRegistered" method="POST" action="RegSuccessServlet"> 
<div id="myList">
</div>
<input type="submit" value="Register" id="Register"/>
</form>

<div id="myListRegisted">
</div>

<br/>
<%
	if(session.getAttribute("message") != null){
%>
Click the link, and read your messages in Log file <a href="http://localhost:8080/PROJET_LO54/MessageConsumerAServlet">Messages</a>
<%
	}
%>
</body>
</html>